package com.foreknow.controller;

import com.foreknow.model.Admin;
import com.foreknow.service.impl.AdminServiceImpl;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonLogin extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        AdminServiceImpl adminService=new AdminServiceImpl();
        String name = req.getParameter("name");
        boolean isRight=adminService.getUsernmaeByUser(name);
        String string=null;
        if (isRight){
            string="{\"isRight\":"+true+"}";
        }else {
            string="{\"isRight\":"+false+"}";
        }
        out.println(string);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
